//
//  MYGAcademicReserveTipView.swift
//  MYDoctor
//
//  Created by Denny on 2024/5/28.
//

import UIKit

class MYGAcademicReserveTipView: UIView {

    @IBOutlet weak var reserveBtn: UIButton!
    @IBOutlet weak var countLB: UILabel!
    @IBOutlet weak var secondLB: UILabel!
    @IBOutlet weak var minLB: UILabel!
    @IBOutlet weak var hourLB: UILabel!
    @IBOutlet weak var dayLB: UILabel!
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    var meeting_id: String = ""
    var tipView:MYGAcademicReserveAlert?
    @IBAction func tapReserve(_ sender: Any) {
        self.rootResponsder().popup.bottomSheet(with: true, bgColor: .black.withAlphaComponent(0.43)) {
            let actionSheet = Bundle.main.loadNibNamed("MYGAcademicReserveAlert", owner: nil)?.first as! MYGAcademicReserveAlert
            self.tipView = actionSheet
            actionSheet.coreTF.text = MYGUserManager.getUser()?.doctor.name
            actionSheet.adddressTF.text = MYGUserManager.getUser()?.doctor.hospital
            actionSheet.couresTF.text = MYGUserManager.getUser()?.doctor.department
            
            actionSheet.tapDismissCompletion = {
                self.rootResponsder().popup.dismissPopup()
            }
  
            actionSheet.tapSureCompletion = {
                self.rootResponsder().popup.dismissPopup()
            }
          
            actionSheet.frame = CGRect.init(x: 0, y: 0, width: screenWidth, height: 345 + bottomSafeheight)
            return actionSheet
        }
    }
    
    private func submit(){
                
        var params:[String:Any] = [:]
        params["meeting_id"] = meeting_id
        params["name"] = self.tipView?.coreTF.text ?? ""
        params["hospital"] = self.tipView?.adddressTF.text ?? ""
        params["department"] = self.tipView?.couresTF.text ?? ""
        
        MYGLoading.show()
        MYGNetwork<MYGHomePageAPI, MYGEmptyModel>.request(target: .meeting_sign(param: params)) {[self] _ in
            MYGLoading.hide()
            MMYGHUD.showToast(text: "预约成功")
            self.rootResponsder().popup.dismissPopup()
            self.reserveBtn.isHidden = true
       } failed: { _, error in
           MYGLoading.hide()
           MMYGHUD.showToast(text: error)
       }
        
        
    }
    
}
